<template>
  <view class="content">
    <u-cell-group>
      <u-swipe-action>
        <u-swipe-action-item @click="action" :options="options" v-for="item in grouplist" :name="item.id" :key="item.id">
          <u-cell :title="item.nickname + '' + ' ' + '( ' + item.store_text + ')'" :label="'最近登录:' + item.logintime_text"
            :value="item.group_text" @click="toedit(item.id)" center>
          </u-cell>
        </u-swipe-action-item>
      </u-swipe-action>
    </u-cell-group>

    <!-- 消息提醒 -->
    <u-toast ref="notice"></u-toast>

    <!-- 模态框 -->
    <u-modal :show="show" :content="content" showCancelButton @confirm="confirm" @cancel="cancel" />
  </view>
</template>

<script>
export default {
  onLoad() {
    this.auth = this.$u.auth.check();
    this.employeelist();
  },
  created() {

    this.timer = setInterval(() => {

      let a = this.$u.count.check()
      console.log(a)

    }, 15000);

  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  data() {
    return {
      auth: {},
      grouplist: [],
      show: false,
      empid: 0,
      content: "",
      content: "是否删除该商品",
      options: [
        {
          text: "添加",
          style: {
            backgroundColor: "#3c9cff",
          },
        },
        {
          text: "删除",
          style: {
            backgroundColor: "#f56c6c",
          },
        },
      ],
    };
  },

  methods: {
    async confirm() {
      let that = this
      // console.log(3234)
      // return false
      that.show = false

      var data = {
        adminid: this.empid
      }



      var result = await this.$u.api.admin.delete(data)

      if (result.code) {
        this.$refs.notice.show({
          type: "success",
          message: result.msg,
          duration: 2000,

        })
        setTimeout(() => {
          this.employeelist();
        }, 350)

        uni.$u.route({
          url: "/pagesB/employee/permission/auth/index"
        })
      } else {
        this.$refs.notice.show({
          type: "error",
          message: result.msg,
          duration: 2500
        })
      }

    },
    cancel() {
      this.show = false
    },

    delete() {
      uni.showModal({
        title: '温馨提示',
        content: '确定要删除吗？',
        success: res => {
          if (res.confirm) {
            this.show = false
          }
        }
      })
    },
    async employeelist() {
      let result = await this.$u.api.admin.employee();
      if (result.code) {
        this.grouplist = result.data;
      }
    },
    toedit(empid) {
      this.$u.route(`/pagesB/employee/permission/auth/edit`, {
        empid: empid,
      });
    },
    action(item) {
      // 添加
      if (item.index == 0) {
        uni.$u.route({
          url: "/pagesB/employee/permission/auth/add",
        });
      }
      // 删除
      if (item.index == 1) {
        this.show = true;
        this.empid = item.name;
      }
    },
  },
};
</script>

<style scoped></style>